import 'dart:typed_data';

class EscCommand {
  Map<String, dynamic> toJson() => {};
}

class TextCommand extends EscCommand {
  int type = 1;
  int? textSize; //字体大小
  int? attribute;
  int? alignment;
  int? absoluteHorizontal = 0;
  int? absoluteVertical = 0;
  String content;

  TextCommand(
    this.content, {
    this.textSize, //文字大小
    this.attribute, //Text属性
    this.alignment, //对齐方式
    this.absoluteHorizontal, //左边距
    this.absoluteVertical,  //上边距
  });

  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = <String, dynamic>{};
    data["type"] = 1;
    data["content"] = content;
    data["textSize"] = textSize;
    data["attribute"] = attribute;
    data["alignment"] = alignment;
    data["absoluteHorizontal"] = absoluteHorizontal;
    data["absoluteVertical"] = absoluteVertical;
    return data;
  }
}

class QrcodeCommand extends EscCommand {
  String data; //二维码内容
  int? alignment;//对齐方式
  int? moduleSize;//二维码大小

  QrcodeCommand(this.data, {this.alignment, this.moduleSize});

  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = <String, dynamic>{};
    data["type"] = 5;
    data["data"] = this.data;
    data["alignment"] = alignment;
    data["moduleSize"] = moduleSize;
    return data;
  }
}

class BarcodeCommand extends EscCommand {
  int type = 4;
  String data;
  int codeType;
  int? width;
  int? height;
  int? alignment;
  int? textPosition;

  BarcodeCommand(this.data,
      {required this.codeType,
      this.width,
      this.height,
      this.alignment,
      this.textPosition});

  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = <String, dynamic>{};
    data["type"] = 4;
    data["data"] = this.data;
    data["codeType"] = codeType;
    data["width"] = width;
    data["height"] = height;
    data["alignment"] = alignment;
    data["textPosition"] = textPosition;
    return data;
  }
}

class ImageCommand extends EscCommand {
  int type = 3;
  Uint8List img; // 图片数据
  int alignment; //对齐方式0：左对齐；1：居中；2：右对齐
  int width; //图片宽度

  ImageCommand(this.img, this.alignment, this.width);

  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = <String, dynamic>{};
    data["type"] = 3;
    data["img"] = img;
    data["width"] = width;
    data["alignment"] = alignment;
    return data;
  }
}

class TableCommand extends EscCommand {
  int type = 2;
  List<String> titles;
  List<int> cells;
  List<List<String>>? rows;

  TableCommand(this.titles, this.cells, {this.rows});

  Map<String, dynamic> toJson() {
    Map<String, dynamic> data = <String, dynamic>{};
    data["type"] = 2;
    data["titles"] = titles;
    data["cells"] = cells;
    data["rows"] = rows;
    return data;
  }
}
